<template>
	<div>
		<el-row>
			<el-col :span="10">
				<el-input placeholder="请输入项目名称" v-model="cheName.name">
					<el-button icon="el-icon-search"></el-button>
				</el-input>
			</el-col>
			<el-col :span="1">
				<el-button type="primary" @click="SearchByName()">查询</el-button>
			</el-col>
		</el-row>
		<br /><br />
		<template>
			<div>
				<el-table :data="tableData" border style="width: 100%" height="750">
					</el-table-column>
					<el-table-column prop="id" label="ID" width="150" height="100">
					</el-table-column>
					<el-table-column prop="medicalid" label="病例ID" width="150">
					</el-table-column>
					<el-table-column prop="registid" label="挂号ID" width="150">
					</el-table-column>
					<el-table-column prop="itemid" label="项目ID" width="150">
					</el-table-column>
					<el-table-column prop="name" label="项目名称" width="150">
					</el-table-column>
					<el-table-column prop="objective" label="目的要求" width="150">
					</el-table-column>
					<el-table-column prop="position" label="检查部位" width="150">
					</el-table-column>
					<el-table-column prop="isurgent" label="是否加急" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.isurgent===1">加急</el-tag>
							<el-tag size="medium" type="primary" v-else="scope.row.isurgent===0">不加急</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="num" label="数量" width="150">
					</el-table-column>
					<el-table-column prop="creationtime" label="开立时间" width="185">
						<template slot-scope="scope">
							<i class="el-icon-time"></i>
							<span style="margin-left: 10px">{{ scope.row.creationtime }}</span>
						</template>
					</el-table-column>
					<el-table-column prop="doctorid" label="开立医生" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.doctorid===1">医院管理员</el-tag>
							<el-tag size="medium" type="success" v-else-if="scope.row.doctorid===2">挂号收费员</el-tag>
							<el-tag size="medium" type="primary" v-else-if="scope.row.doctorid===3">门诊医生</el-tag>
							<el-tag size="medium" type="#ff007f" v-else-if="scope.row.doctorid===4">医技医生</el-tag>
							<el-tag size="medium" type="info" v-else-if="scope.row.doctorid===5">药房操作员</el-tag>
							<el-tag size="medium" type="warning" v-else>财务管理员</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="checkoperid" label="检查人员" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.checkoperid===1">医院管理员</el-tag>
							<el-tag size="medium" type="success" v-else-if="scope.row.checkoperid===2">挂号收费员</el-tag>
							<el-tag size="medium" type="primary" v-else-if="scope.row.checkoperid===3">门诊医生</el-tag>
							<el-tag size="medium" type="#ff007f" v-else-if="scope.row.checkoperid===4">医技医生</el-tag>
							<el-tag size="medium" type="info" v-else-if="scope.row.checkoperid===5">药房操作员</el-tag>
							<el-tag size="medium" type="warning" v-else>财务管理员</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="resultoperid" label="结果录入人员" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.resultoperid===1">医院管理员</el-tag>
							<el-tag size="medium" type="success" v-else-if="scope.row.resultoperid===2">挂号收费员</el-tag>
							<el-tag size="medium" type="primary" v-else-if="scope.row.resultoperid===3">门诊医生</el-tag>
							<el-tag size="medium" type="#ff007f" v-else-if="scope.row.resultoperid===4">医技医生</el-tag>
							<el-tag size="medium" type="info" v-else-if="scope.row.resultoperid===5">药房操作员</el-tag>
							<el-tag size="medium" type="warning" v-else>财务管理员</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="checktime" label="检查时间" width="185">
						<template slot-scope="scope">
							<i class="el-icon-time"></i>
							<span style="margin-left: 10px">{{ scope.row.checktime}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="result" label="检查结果" width="200">
					</el-table-column>
					<el-table-column prop="resulttime" label="结果时间" width="185">
						<template slot-scope="scope">
							<i class="el-icon-time"></i>
							<span style="margin-left: 10px">{{ scope.row.resulttime}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="state" label="状态" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.state===2">开立</el-tag>
							<el-tag size="medium" type="primary" v-else-if="scope.row.state===1">暂存</el-tag>
							<el-tag size="medium" type="warning" v-else>其他</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="recordtype" label="记录类型" width="150">
						<template slot-scope="scope">
							<el-tag size="medium" type="danger" v-if="scope.row.recordtype===1">检验</el-tag>
							<el-tag size="medium" type="primary" v-else-if="scope.row.recordtype===2">检查</el-tag>
							<el-tag size="medium" type="warning" v-else>处置</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="操作" width="150">
						<template slot-scope="scope">
							<el-button type="primary" icon="el-icon-edit" size="mini" @click="Edit(scope.row.id)">
							</el-button>
							<el-button type="danger" icon="el-icon-delete" size="mini"
								@click="deleteById(scope.row.id)"></el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</template>
		<el-drawer title="项目信息" :visible.sync="drawer" size="50%">
			<!-- <el-col :span="4">
				<el-tag>查看项目ID</el-tag>
			</el-col>
			<el-col :span="2">
					<el-button icon="el-icon-search" circle></el-button>
			</el-col>
			<br /><br /><br /> -->
			<el-form>
				<el-form-item prop="id" label="ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.id" style="width: 700px;" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item prop="medicalid" label="病例ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.medicalid" style="width: 700px;" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item prop="registid" label="挂号ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.registid" style="width: 700px;" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item prop="itemid" label="项目ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.itemid" style="width: 700px;">
						<el-button slot="append" icon="el-icon-search" @click="GetFme()"></el-button>
					</el-input>
				</el-form-item>
				<el-form-item prop="name" label="项目名称" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.name" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="objective" label="目的要求" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.objective" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="position" label="检查部位" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.position" style="width: 700px;"></el-input>
				</el-form-item>
				<!-- <el-form-item prop="isurgent" label="是否加急" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.isurgent" style="width: 700px;"></el-input>
				</el-form-item> -->
				<el-form-item prop="num" label="数量" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.num" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="creationtime" label="开立时间" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.creationtime" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="doctorid" label="开立医生ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.doctorid" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="checkoperid" label="检查人员ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.checkoperid" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="resultoperid" label="结果录入人ID" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.resultoperid" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="checktime" label="检查时间" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.checktime" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="result" label="检查结果" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.result" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="resulttime" label="结果时间" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.resulttime" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="recordtype" label="记录类型" :label-width="formLabelWidth">
					<el-input v-model="CheckMess.recordtype" style="width: 700px;"></el-input>
				</el-form-item>
				<el-form-item prop="isurgent" label="是否加急" :label-width="formLabelWidth">
					<!-- <el-input v-model="CheckMess.isurgent" style="width: 700px;"></el-input> -->
					<el-switch v-model="CheckMess.isurgent" active-color="#ff0004" inactive-color="#409EFF"
						active-value="1" inactive-value="0" active-text="加急" inactive-text="不加急">
					</el-switch>
				</el-form-item>
			</el-form>
			<!-- <div slot="footer" class="dialog-footer"> -->
			<el-button type="success" @click="ToStorage()">暂存</el-button>
			<el-button type="primary" @click="ToOpen()">开立</el-button>
			<!-- </div> -->
		</el-drawer>
		<el-dialog title="非药品收费项目详情" :visible.sync="dialogTableVisible">
			<el-table :data="FmeData" border style="width: 80%" height="750px">
				<el-table-column property="id" label="ID" width="150"></el-table-column>
				<el-table-column property="itemcode" label="项目编码" width="280"></el-table-column>
				<el-table-column property="itemname" label="项目名称" width="350"></el-table-column>
			</el-table>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: "ExamineApplication",
		data() {
			return {
				tableData: [],
				FmeData: [],
				cheName: {
					name: '',
				},
				CheckMess: {
					isurgent: '1'
				},
				formLabelWidth: '100px',
				dialogTableVisible: false,
				dialogFormVisible: false,
				drawer: false
			}
		},
		created() {
			let url = '/CheckApply/selectAll'
			this.$axios.post(url)
				.then((resp) => {
					this.tableData = resp.data;
					// console.log(this.tableData)
				})
		},
		methods: {
			SearchByName() {
				let url = '/CheckApply/selectByName'
				let param = this.$qs.stringify(this.cheName)
				this.$axios.post(url, param)
					.then((resp) => {
						// console.log('--this.med.id', resp.casenumber);
						this.tableData = resp.data;
						console.log('this.tableData=', this.tableData)
					})
			},
			async deleteById(id) {
				const confirmResult = await this.$confirm('此操作将永久删除项目信息, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).catch(err => err)
				if (confirmResult !== 'confirm') {
					return this.$message.info('已取消删除');

				}
				console.log('确认了删除')
				const {
					data: res
				} = await this.$http.delete("/CheckApply/delete?id=" + id);
				this.FindAll();
				window.location.reload();
				let i = res
				// console.log("i="+i)
				if (i > 0) {
					return this.$message.success("删除成功");
				} else {
					return this.$message.error("该项目为开立状态,禁止删除!");
				}
				this.FindAll();
				window.location.reload();
			},
			// deleteById(row){
			// 	let url = '/CheckApply/delete';
			// 	let param = this.$qs.stringify(this.row);
			// 	console.log("row="+row)
			// 	console.log("param="+param)
			// 	this.$axios.post(url,param)
			// 		.then((resp) => {
			// 			let i = resp.data;
			// 			if(i>0){
			// 				alter("删除成功!")
			// 			}else{
			// 				alert("状态为开立，删除失败!")
			// 			}
			// 		})
			// }	
			Edit(id) {
				//显示弹窗
				// this.dialogFormVisible = true
				this.drawer = true;
				let url = '/CheckApply/selectById';
				// console.log(id);
				let param = {};
				param.id = id;
				param = this.$qs.stringify(param);
				this.$axios.post(url, param)
					.then((resp) => {
						this.CheckMess = resp.data;
						// console.log(this.CheckMess);
					})

			},
			FindAll() {
				let url = '/CheckApply/selectAll'
				this.$axios.post(url)
					.then((resp) => {
						this.tableData = resp.data;
					})
			},
			ToStorage() {
				let url = '/CheckApply/updateToS';
				// let param = this.CheckMess;
				// console.log("---param="+param)
				let param = this.$qs.stringify(this.CheckMess)
				console.log("---param=" + param)
				this.$axios.post(url, param)
					.then((resp) => {
						let i = resp.data;
						if (i > 0) {
							return this.$message.success("暂存成功!");
						} else {
							return this.$message.error('暂存失败!')
						}
					})
					.catch((err) => {
						console.log('error=', err)
					})
				// this.dialogFormVisible = false;
				this.drawer = false;
				this.FindAll();
				window.location.reload()
			},
			ToOpen() {
				let url = '/CheckApply/updateToO';
				let param = this.$qs.stringify(this.CheckMess)
				// console.log("---param="+param)
				this.$axios.post(url, param)
					.then((resp) => {
						let i = resp.data;
						if (i > 0) {
							return this.$message.success("开立成功!");
						} else {
							return this.$message.error('开立失败!')
						}
					})
					.catch((err) => {
						console.log('error=', err)
					})
				// this.dialogFormVisible = false;
				this.drawer = false;
				this.FindAll();
				window.location.reload()
			},
			GetFme() {
				let url = '/FmedItem/selectAll'
				this.$axios.post(url)
					.then((resp) => {
						this.FmeData = resp.data;
					})
				this.dialogTableVisible = true
			}
		}
	}
</script>

<style scoped>

</style>
